package com.nuc6.controller;

import com.nuc6.entity.InterviewArrangement;
import com.nuc6.entity.QuestionManage;
import com.nuc6.mapper.DoscoreMapper;
import com.nuc6.mapper.MyquestionMapper;
import com.nuc6.mapper.QuestionManageMapper;
import com.nuc6.service.DoscoreService;
import com.nuc6.service.InterviewArrangementService;
import com.nuc6.service.MyquestionService;
import com.nuc6.service.QuestionManageService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zwp
 * @version 1.0
 */
@Controller
public class InterviewerController {
    @Resource
    private InterviewArrangementService interviewArrangementService;
    @Resource
    private MyquestionService myquestionService;
    @Resource
    private QuestionManageService questionManageService;
    @Resource
    private MyquestionMapper myquestionMapper;
    @Resource
    private QuestionManageMapper questionManageMapper;
    @Resource
    private DoscoreMapper doscoreMapper;
    @GetMapping("/interviewer")
    public String toInterviewer(){
        return "interviewer";
    }
    @GetMapping("/result")
    public String toResult(HttpServletRequest request,
                           HttpSession session){
        Object getTel = session.getAttribute("tel");
        String tel = getTel.toString();
        String score = doscoreMapper.getScore(tel);
        request.setAttribute("score",score);

        return "result";
    }
    @GetMapping("/myQuestion")
    public String toMyQuestion(HttpServletRequest request,
                               HttpSession session,
                               Model model){
        Object getTel = session.getAttribute("tel");
        String tel = getTel.toString();
        String type = myquestionMapper.getType(tel);
        if(type == null){
            model.addAttribute("msg","暂无面试题");
            return "interviewer";
        }
        QuestionManage question = questionManageMapper.getQuestion(type);
        request.setAttribute("questions",question);

        return "myQuestion";
    }
    @GetMapping("/interview")
    public String toInterview(HttpServletRequest request){
        List<InterviewArrangement> interview = interviewArrangementService.list();
        request.setAttribute("interview",interview);
        return "interview";
    }


}
